import * as type from './type'

import axios from 'axios'

// import qs from 'queryString'



const state = {
    getlist:null
}

export const actionCreators={
    get_list(fcate,val){
        //使用了redux-thunk之后，此处应该这么写
        return dispatch=>{//返回一个回调函数
            
         axios ({
             url:'/gsort',
             params:{
                key: {"cdt":{"is_show_presale":"0","hot_show_type":1,"fcate":fcate,"sale_type":2},"order":{"show_stime":"desc","sales":"desc","fav":"desc","sort":"desc"}},
                type: 50,
                zhouyi_ids: 'p8_c4_l4',
                machining: 'danpin',
                page: val,
                rows: 10,
                dtype: 'json',
                price_range:'', 
                cat_threeids: '',
                filter_id: '',
                callback: 'gsort_callback'
             }
         })
         .then ( data => {
             console.log( 'stydtf',data.data.list )
            const action = {
                type:type.GET_LIST,
                payload:data.data
            }
            dispatch(action)
         } )
         .catch( error => console.log( error ) )
        }     
    }
}

export const reducer=( previousState = state , action)=>{
    const newState = {
        ...previousState
    }
    switch (action.type) {
        case type.GET_LIST:
            newState.getlist=action.payload.list//赋值
            break;
        default:
            break;
    }
    return newState//千万别忘了写返回值
}
